﻿//Create by: TamHNM
//Create Date: 19/1/2015
//Last Modify By: TamHNM
//last Modify Date: 19/1/2015

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ANZ_AIM_BLL;
using ANZ_AIM_BLL.Model;
using ANZ_AIM_GUI.Utils;
using log4net;

namespace ANZ_AIM_GUI
{
    public partial class frmSystemInformation : Form
    {
        //log4net
        private static readonly ILog logger = LogManager.GetLogger(typeof(frmSystemInformation));

        List<Configuration> configurationList = new List<Configuration>();

        public frmSystemInformation()
        {
            InitializeComponent();
        }

        private void loadSettings()
        {
            try
            {
                ConfigurationBLL configurationBLL = new ConfigurationBLL();
                Configuration configuration = configurationBLL.GetByKey(Configuration.MAX_FILE_SIZE_UPLOAD);
                configurationList.Add(configuration);
                txtMaxFileSizeUpload.Text = configuration.ConfigValue;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error when load system configuration!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }

        private void frmSystemInformation_Load(object sender, EventArgs e)
        {
            loadSettings();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtMaxFileSizeUpload.Text.Trim()))
                {
                    MessageBox.Show("Max File Size Upload cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtMaxFileSizeUpload.Focus();
                    return;
                }

                configurationList[0].ConfigValue = txtMaxFileSizeUpload.Text;
                ConfigurationBLL configurationBLL = new ConfigurationBLL();
                configurationBLL.UpdateConfiguration(configurationList);  
                MessageBox.Show("Data was saved successfully!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            { 
                MessageBox.Show("Error when save data!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
